// Requires "request" to be installed (see https://www.npmjs.com/package/request)
var request = require('request')
var fs = require('fs')

request.post(
    {
        url: 'https://api.remove.bg/v1.0/removebg',
        formData: {
            image_file: fs.createReadStream('file.jpg'),
            size: 'auto'
        },
        headers: {
            'X-Api-Key': 'eBuH8yqyZr6XxxkQsyk3qk4A'
        },
        encoding: null
    },
    function(error, response, body) {
        if (error) return console.error('Request failed:', error)
        if (response.statusCode != 200)
            return console.error(
                'Error:',
                response.statusCode,
                body.toString('utf8')
            )
        fs.writeFileSync('no-bg.png', body)
    }
)
